package base;

import java.util.Random;

/**
 * Generate exponential number via the nextInt() method.
 * 
 * @author rweiller
 */
public class Exponential
{
	public Random	x;
	public int		m;

	/**
	 * Create an exponential generator
	 * 
	 * @param seed the first seed
	 * @param m the medium
	 */
	public Exponential(int seed, int m)
	{
		if (m < 1)
		{
			throw new IllegalArgumentException("Config file : exp.rd.seed.m must be > 0");
		}
		this.x = new Random(seed);
		this.m = m;
	}

	/**
	 * @return the next exponential number
	 */
	public double nextDouble()
	{
		double aNumber;
		do
		{
			aNumber = -m * Math.log(x.nextDouble());
		} while (aNumber < 0);
		return aNumber;
	}
}
